﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TaxAssistantBase;

namespace ShiBieProject
{
    class InvoiceOverallVerification
    {
        public static void overallVerification(List<InvoiiceOcrModel> bpmlist) {
            int tiaoNim = 0;
            foreach (InvoiiceOcrModel iom in bpmlist) {
                try
                {
                    if (iom.companyState == "1")
                    {
                        continue;
                    }
                    if (iom.billtype != -1)
                    {
                        if (iom.invoiceOcrSonLists != null)
                        {
                            if (iom.invoiceOcrSonLists.Count > 0)
                            {
                                string CompanyState = iom.companyState;
                                string totalStateMoney = iom.invoiceOcrSonLists[0].totalStateMoney;
                                string billingDateState = iom.invoiceOcrSonLists[0].invoiceDate;
                                string invoicetypeState = iom.invoiceOcrSonLists[0].invoicetypeState;
                                string isProviderOrCustomer = iom.invoiceOcrSonLists[0].isProviderOrCustomer;
                                string vendorState = "";
                                if (isProviderOrCustomer == "0")
                                {
                                    vendorState = iom.invoiceOcrSonLists[0].gfcompanynameState;
                                }
                                else if (isProviderOrCustomer == "1")
                                {
                                    vendorState = iom.invoiceOcrSonLists[0].xfcompanynameState;
                                }
                                bool mingxiNeiRongState = getmingxiNeiRongState(iom.invoiceOcrDetailedDtoList);
                                if (totalStateMoney != "1" || (!string.IsNullOrEmpty(billingDateState)) || (!string.IsNullOrEmpty(invoicetypeState)) || (!string.IsNullOrEmpty(vendorState)))
                                {
                                    if (CompanyState == "1" || CompanyState == "3")
                                    {
                                        iom.companyState = CompanyOrMoneyStateEnum.InvoiceCheckNeiRong;//修改内容
                                    }
                                    else
                                    {
                                        iom.companyState = CompanyOrMoneyStateEnum.InvoiceCheckCompanyNameAndNeiRong;//核验公司和内容
                                    }
                                }
                                else if (totalStateMoney == "1" && (string.IsNullOrEmpty(billingDateState)) && (string.IsNullOrEmpty(invoicetypeState)) && (string.IsNullOrEmpty(vendorState)))
                                { 
                                    if (CompanyState == "1" || CompanyState == "3")
                                    {
                                        iom.companyState = CompanyOrMoneyStateEnum.InvoiceAbsolutelyRight;//完全正确
                                    }
                                    else
                                    {
                                        iom.companyState = CompanyOrMoneyStateEnum.InvoiceCheckCompanyName;//修改公司
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    WsdLogger.yxlog("error", "第" + tiaoNim + "条得到总状态错误" + ex.Message);
                    continue;
                }
               
            }

        }

        private static bool getmingxiNeiRongState(List<invoiceOcrDetailedModel> invoiceOcrDetailedDtoList)
        {
            if (invoiceOcrDetailedDtoList!=null) {
                foreach (invoiceOcrDetailedModel iod in invoiceOcrDetailedDtoList) {
                    string neirongState = iod.productNameState;
                    if (neirongState=="30") {
                        return false;
                    }
                }
            }
            return true;
        }
    }
}
